<template>
  <div class="steps">
    <!-- {{ isSeeProcess }}{{!process[0].active}} -->
    <!-- 当前登录人 -->
    <div class="top">
      <div class="top_title">
        <div class="title" style="background: none">申报流程</div>
        <div class="type">项目类型:{{ pTypeName }}</div>
      </div>
      <div class="process">
        <div v-for="(i, index) in process" :key="index" class="process_item">
          <div class="left">
            <div class="img" :class="i.active ? 'activeBg' : ''">
              <img :src="i.imgSrc" class="step_img" />
              <p class="index" :class="i.active ? 'active' : ''">
                {{ index + 1 }}
              </p>
            </div>
            <img
              src="@/assets/static/imgs/down.png"
              v-if="index != process.length - 1"
              class="down"
            />
          </div>
          <div class="right">
            <div class="right_top">
              <p class="processName" :class="i.active ? 'active' : ''">
                {{ i.processName }}
              </p>

              <div v-if="index == 0" class="processText">
                <p v-if="i.status == 0" :class="i.active ? 'activeBgLG' : ''">
                  待申报
                </p>
                <p v-if="i.status == 1" class="isStatus">已申报</p>
              </div>
              <div v-else class="processText">
                <div v-if="i.processName == '补充材料'">
                  <p v-if="i.status == 0" class="noActiveBgLG">未补充</p>
                  <p v-if="i.status == 1" class="isStatus">已补充</p>
                </div>
                <div v-else-if="i.processName == '登记结果'">
                  <p v-if="i.status == 0" class="noActiveBgLG">未登记</p>
                  <p v-if="i.status == 1" class="isStatus">已登记</p>
                </div>
                <div v-else>
                  <p v-if="i.status == 0" class="noActiveBgLG">未审核</p>
                  <p v-if="i.status == 1" class="isStatus">已审核</p>
                </div>
              </div>
            </div>

            <div class="right_bottom" v-if="i.list">
              <div v-for="(i, index) in i.list" :key="index" class="item">
                <div>
                  <span class="createBy">{{ i.createBy }}</span>
                  <span class="approveResult0" v-if="i.approveResult == 0">
                    已通过
                  </span>
                  <span class="approveResult1" v-if="i.approveResult == 1">
                    已驳回
                  </span>
                  <span class="approveResult9" v-if="i.approveResult == 9">
                    已拒绝
                  </span>
                  <p class="updateTime">{{ i.updateTime }}</p>
                </div>
                <p class="comment">{{ i.comment }}</p>
              </div>
            </div>
            <div class="right_bottom" v-if="index == 0 && !i.list">
              <p>{{ loginUser.name }}</p>
            </div>
            <div class="process_file" v-if="i.specialistAppendixUrl">
              <div
                v-if="JSON.parse(i.specialistAppendixUrl).length"
                class="file_name"
              >
                <p style="width: 60px">附件：</p>
                <el-link
                  style="margin: 0 16px"
                  type="primary"
                  v-for="(file, index) in JSON.parse(i.specialistAppendixUrl)"
                  :key="index"
                >
                  <span @click="openFile(file)">
                    {{ file.fileName }}
                  </span>
                </el-link>
              </div>
            </div>

            <div
              class="status"
              v-if="!process[0].active && isSeeProcess && i.active"
            >
              <div class="tops top">审核</div>
              <div class="center">
                <img
                  style="
                    width: 2rem;
                    height: 2rem;
                    border-radius: 50%;
                    margin-right: 1rem;
                  "
                  :src="loginUser.avatar"
                />
                管理员:{{ loginUser.name }}
              </div>
              <div class="bottom">
                <el-button
                  size="small"
                  type="danger"
                  @click="rejectApplyBtn(i)"
                >
                  驳 回
                </el-button>
                <el-button
                  size="small"
                  type="success"
                  @click="adoptApplyBtn(i)"
                >
                  通 过
                </el-button>
                <el-button size="small" type="warning" @click="refuseClick">
                  拒 绝
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <adoptApply
      :isShowAdopt="isShowAdopt"
      @adoptApplyFn="adoptApplyFn"
      :processObj="processObj"
    />
    <rejectApply
      :isShowReject="isShowReject"
      @examineFn="examineFn"
      :processObj="processObj"
    />
  </div>
</template>

<script>
import { serverUrl } from "@/look";
import adoptApply from "../components/adoptApply.vue"; // 通过
import rejectApply from "../components/rejectApply.vue"; // 驳回
import { Base64 } from "js-base64";

import {
  apiApproveProject,
  apiZhuanjiaFile, //专家评审中的附件
} from "@/api2/projectManagement/examine";

export default {
  components: {
    adoptApply,
    rejectApply,
  },
  props: {
    active: {
      type: Number,
      default: 0,
    },
  },
  computed: {
    pTypeName() {
      return this.$store.state.project.projectInfo.typeName;
    },
    projectId() {
      return this.$route.params.id;
    },

    process() {
      return this.$store.state.project.projectInfo.processList;
    },

    // 是查看流程还是审批
    isSeeProcess() {
      return this.$store.state.project.projectInfo.isSeeProcess;
    },
  },
  watch: {},
  data() {
    return {
      isShowAdopt: false, // 显示通过
      isShowReject: false, // 显示驳回
      loginUser: JSON.parse(sessionStorage.getItem("loginUserinfo")),

      chooseItemType: {},
      processObj: {},
    };
  },

  mounted() {},
  methods: {
    // 附件预览
    openFile(e) {
      console.log(e);
      window.open(
        serverUrl +
          "onlinePreview?url=" +
          encodeURIComponent(Base64.encodeURI(e.url))
      );
    },
    // 显示驳回面板
    rejectApplyBtn() {
      this.isShowReject = true;
    },
    // 显示通过面板
    adoptApplyBtn(i) {
      this.processObj = i;
      this.isShowAdopt = true;
    },

    // 通过
    async adoptApplyFn(i, params) {
      // 1 提交
      if (i == 1) {
        let data1 = {
          projectId: this.projectId,
          approveResult: params.approveResult,
        };

        let data = {
          projectId: this.projectId,
          specialistAppendixUrl: JSON.stringify(params.specialistAppendixUrl),
        };

        apiApproveProject(data1)
          .then((res) => {
            if (res.code == 0) {
              apiZhuanjiaFile(data)
                .then((res) => {
                  console.log(res);
                  if (res.code == 0) {
                    this.msgSuccess("操作成功");
                    this.$router.push("/projectManagement/approveReport");
                  } else {
                    this.msgError("操作失败");
                  }
                })
                .catch((err) => {
                  console.log(err);
                  this.msgError("操作失败");
                });
            } else {
              this.msgError("操作失败");
            }
          })
          .catch((err) => {
            console.log(err);
            this.msgError("操作失败");
          });

        this.isShowAdopt = false;
      } else {
        this.isShowAdopt = false;
      }
    },

    // 驳回 i==1 驳回， 1!=1 取消
    examineFn(i, params) {
      if (i == 1) {
        let data1 = {
          projectId: this.projectId,
          approveResult: params.approveResult,
          comment: params.comment,
        };

        let data = {
          projectId: this.projectId,
          specialistAppendixUrl: JSON.stringify(params.specialistAppendixUrl),
        };

        // params.projectId = this.projectId;
        apiApproveProject(data1)
          .then((res) => {
            if (res.code == 0) {
              apiZhuanjiaFile(data)
                .then((res) => {
                  console.log(res);
                  if (res.code == 0) {
                    this.msgSuccess("操作成功");
                    this.$router.push("/projectManagement/approveReport");
                  } else {
                    this.msgError("操作失败");
                  }
                })
                .catch((err) => {
                  console.log(err);
                  this.msgError("操作失败");
                });
            } else {
              this.msgError("驳回失败");
            }
          })
          .catch((err) => {
            console.log(err);
            this.msgError("驳回失败");
          });
        this.isShowReject = false;
      } else {
        this.isShowReject = false;
      }
    },

    // 拒绝
    refuseClick() {
      this.$confirm(`确定拒绝该申报立项的审批吗？`, {
        type: "warning",
      })
        .then(async () => {
          const params = {
            projectId: this.projectId,
            approveResult: 9,
          };
          const res = await apiApproveProject(params);
          this.msgSuccess("操作成功");
          this.$router.push("/projectManagement/approveReport");
        })
        .catch(() => {});
    },

    clickStepItem(i) {
      this.$emit("stepItemFn", i);
    },
  },
};
</script>

<style lang="scss" scoped>
p {
  margin: 0;
  padding: 0;
}

.active {
  color: #0b847b;
}
.activeBg {
  background: #0b847b !important;
}
.activeBgLG {
  background-image: linear-gradient(to right, #ff992b, #ffc956);
}

.isStatus {
  background-image: linear-gradient(to right, #49b55b, #92dd6f);
}

.noActiveBgLG {
  background-image: linear-gradient(to right, #9cafc6, #bacfe9);
}

.steps {
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  .status {
    padding: 1rem 0;
    width: 100%;
    // height: 12.5rem;
    background: #fff;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    .tops {
      height: 0px !important;
      line-height: 0px;
      border-left: #0b847b 3px solid;
    }
    .center {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      width: 100%;
      height: 2.5rem;
      margin: 0.5rem 0;
      background: #e7f2ff;
      border-radius: 4px;
      padding-left: 1.25rem;
    }
  }
  .top {
    padding: 1rem 0;
    width: 100%;
    background: #fff;
    height: 3.75rem;
    .top_title {
      margin-left: 1rem;
      padding-left: 1rem;
      padding-right: 1rem;
      height: 1.25rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-left: 3px solid #0b847b;
    }

    font-size: 0.875rem;
    font-weight: bold;
    color: #364a71;
    box-sizing: border-box;
    .type {
      background: #e7f2ff;
      border-radius: 4px;
      padding: 0.5rem;
      font-weight: 500;
      color: #0b847b;
    }
    .process {
      width: 100% !important;
      padding: 1rem 1rem;
      background: #fff;

      .process_item {
        display: flex;
        margin-top: 1.4rem;
        margin-bottom: 3.4rem;
        .left {
          flex: 1;
          text-align: center;
          .img {
            width: 3.125rem;
            height: 3.125rem;
            border-radius: 50%;
            position: relative;
            background: #a1b6cf;
            .step_img {
              position: absolute;
              left: 50%;
              top: 50%;
              transform: translate(-50%, -50%);
            }
            .index {
              position: absolute;
              right: 0;
              bottom: 0;
              z-index: 10;

              width: 1rem;
              height: 1rem;
              line-height: 1rem;
              text-align: center;
              background: #ffffff;
              box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.25);
              border-radius: 50%;
            }
          }
          .down {
            margin-top: 0.6rem;
            width: 0.6rem;
            height: 100%;
          }
        }
        .right {
          flex: 6;
          position: relative;
          .right_top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            div {
              height: 1.25rem;
            }
            .processText {
              height: 1.25rem;
              p {
                padding: 0.2rem 0.5rem;
                font-size: 0.75rem;
                color: #ffffff;
                transform: skew(-20deg);
              }
            }
          }
          .right_bottom {
            margin-top: 1rem;
            margin-bottom: 1rem;
            .item {
              padding-left: 0.625rem;
              line-height: 2.5rem;
              background: #e7f2ff;
              border-radius: 0.25rem;
              div {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 0 0.5rem;
                // .createBy {
                // }
                .approveResult0,
                .approveResult1,
                .approveResult9 {
                  height: 20px;
                  line-height: 20px;
                  font-weight: normal;
                  font-size: 0.8rem;
                  color: #ffffff;
                  padding: 0 0.2rem;
                  border-radius: 4px;
                }
                .approveResult0 {
                  background: #49b55b;
                }
                .approveResult1 {
                  background: #e86565;
                }
                .approveResult9 {
                  background: #e6a23c;
                }
                .updateTime {
                  font-size: 0.8rem;
                  color: #999999;
                }
              }
              .comment {
                font-weight: normal;
                color: #0b847b;
                font-size: 0.9rem;
              }
            }
          }
          .process_file {
            .file_name {
              display: flex;
            }
          }
          .right_btn {
            margin-top: 1rem;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: left;
          }
        }
      }
    }
  }

  .item {
    cursor: pointer;
  }
}
</style>
